package com.risen.project.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ResourceBundle;

@Configuration
public class MybatisPlusConfig {

    private static String driverClassName = null;

    static {
        ResourceBundle resource = ResourceBundle.getBundle("application");
        driverClassName = resource.getString("spring.datasource.driver-class-name");
    }

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        if (driverClassName.contains("mysql")) {
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        } else if (driverClassName.contains("dm")) {
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.DM));
        }
        return interceptor;
    }
}
